<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" size="mini"  v-show="showSearch" label-width="68px">
      <el-row :gutter="20">
        <el-col :span="4">
          <el-form-item label="项目区域" prop="projectRegion">
            <el-select v-model="queryParams.projectRegion" placeholder="请选择" clearable
              @keyup.enter.native="handleQuery">
              <el-option v-for="dict in dict.type.cld_project_region" :key="dict.value" :label="dict.label"
                :value="parseInt(dict.value)"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="项目名称" prop="projectName">
            <el-input v-model="queryParams.projectName" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="员工姓名" prop="staffName">
            <el-input v-model="queryParams.staffName" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="时间区域" prop="month">
            <el-date-picker v-model="dateRange" value-format="yyyy-MM-dd" type="daterange" range-separator="-"
              start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label-width="10px">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="CldPayDetailsList" border>
      <el-table-column label="项目区域" align="center">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cld_project_region" :value="scope.row.projectRegion" />
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="员工编号" align="center" prop="staffNo" width="80px;"/>
      <el-table-column label="员工姓名" align="center" prop="staffName" />
      <el-table-column label="身份证号" align="center" prop="staffIdcard" width="200px;"/>
      <el-table-column label="银行卡号" align="center" prop="bankCard" width="200px;"/>
      <el-table-column label="联系电话" align="center" prop="staffPhone" />
      <el-table-column label="基本工资" align="center" prop="basicSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.basicSalary) }}
        </template>
      </el-table-column>
      <el-table-column label="岗位津贴" align="center" prop="basedSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.basedSalary) }}
        </template>
      </el-table-column>
      <el-table-column label="加班工资" align="center" prop="overtimeSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.overtimeSalary) }}
        </template>
      </el-table-column>
      <el-table-column label="福利金额" align="center" prop="welfareSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.welfareSalary) }}
        </template>
      </el-table-column>
      <el-table-column label="奖励金额" align="center" prop="awardSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.awardSalary) }}
        </template>
      </el-table-column>
      <el-table-column label="保险费用" align="center" prop="insuranceSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.insuranceSalary) }}
        </template>
      </el-table-column>
      <el-table-column label="工服费用" align="center" prop="clothesSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.clothesSalary) }}
        </template>
      </el-table-column>
      <el-table-column label="罚款金额" align="center" prop="fineSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.fineSalary) }}
        </template>
      </el-table-column>
      <el-table-column label="工作计划" align="center" prop="workSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.workSalary) }}
        </template>
      </el-table-column>
      <el-table-column label="实付金额" align="center">
        <template slot-scope="scope">
          {{ calculateSalary(scope.row) }}
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { selectSalaryStatistics } from "@/api/cld/CldPayDetails";

export default {
  name: "CldPayDetails",
  dicts: ['cld_project_region'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
        // 时间区间
        dateRange: [],
      // 薪酬管理表格数据
      CldPayDetailsList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectRegion: null,
        projectName: null,
        staffName: null
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询薪酬管理列表 */
    getList() {
      this.loading = true;
      selectSalaryStatistics(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.CldPayDetailsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
     // 计算实发工资
     calculateSalary(row) {
      let money = row.basicSalary + row.basedSalary + row.overtimeSalary + row.welfareSalary + row.awardSalary + row.insuranceSalary + row.clothesSalary +
      row.fineSalary + row.workSalary;
      return this.toMoney(money);
    },
  }
};
</script>
<style scoped>
.el-range-editor.el-input__inner {
  width: 100%;
}

.el-select {
  width: 100%;
}
</style>
